import Vue from 'vue'
import Router from 'vue-router'
import headpage from './headpage/Topnav'
Vue.use(Router)

const router = new Router(
  {
    // mode: 'history',  //去掉#号
    routes: headpage // 多个路由要加冒号
  },
)
// router.beforeEach((to, from, next) => {
  // var ua = window.navigator.userAgent.toLowerCase(); 
  // if(ua.match(/MicroMessenger/i) == 'micromessenger') { //判断是不是微信浏览器
  //   if(to.meta.auth){ //判断是不是必须要登录
  //     if(sessionStorage.getItem('token') == null){ //判断是不是已经登陆过了
  //       var url = location.search; //获取url中"?"符后的字串 
  //       var theRequest = new Object(); //new一个对象
  //       if (url.indexOf("?") != -1) {
  //         var str = url.substr(1);
  //         if (str.indexOf("&") != -1) {
  //           var strs = str.split("&");
  //           for (var i = 0; i <strs.length; i++) {
  //             theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
  //           }
  //         } else {
  //           theRequest[str.split("=")[0]] = unescape(str.split("=")[1]);
  //         }
  //       }
  //       var codes = theRequest.code;        
  //       if(codes != null || codes != undefined){ //判断有没有授权
  //         $$.ajax({
  //           type : "GET",
  //           url: "http://www.iplan-ad.com/api/auth/wechat/getWXUserInfo",
  //           data: {
  //             'code':codes
  //           },
  //           success:(response=>{
  //             alert(56456456)
  //             console.log(response)
  //             sessionStorage.setItem('openId',response.oppenid)
  //             sessionStorage.setItem('token',response.token)
  //             if(response.iplanCode == 101){
  //               sessionStorage.setItem('unionid',response.userinfo.unionid)
  //               next({path:'/bomNav/Verification'})             
  //             }   
  //             next()   
  //           }),
  //           error:((err)=>{
  //             alert(err)
  //             next()
  //           })
  //         })
  //         next()
  //       }else{
  //         var url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxfefc1188cb991ef1&redirect_uri=http%3a%2f%2fwww.iplan-ad.com%2fapp%2f%23"+to.path+"&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect"
  //         location.replace(url)
  //       }
  //     }else{
  //       localStorage.removeItem('token')
  //       next()
  //     }
  //   }else{
  //     next()
  //   }
  // }else{ 
  //   var url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxfefc1188cb991ef1&redirect_uri=http%3a%2f%2fwww.iplan-ad.com%2fapp%2f%23%2fbomNav&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect"
  //   location.replace(url)
  // }
// })
export default router


